package com.ttx.rabbitmq.demo.mq.subscribe;

import com.ttx.rabbitmq.demo.config.RabbitMqConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 *
 * @author TimFruit
 * @date 20-1-11 下午11:30
 */
@Slf4j
@Component
public class LogsQueueMessageListener2 implements MessageListener {

    //exclusive=true, 标明只能有一个消费者获取该队列的数据
    @RabbitListener(queues = RabbitMqConfig.PUBLISH_SUBSCRIBE_LOGS_QUEUE_NAME_2, exclusive = true)
    @Override
    public void onMessage(Message message) {
        byte[] body=message.getBody();
        String msgStr=new String(body);
        log.info("logs.consumer.2 收到一条消息: "+msgStr);
    }

}
